<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Confirm Before Leave</title>
<script language="javascript" type="text/javascript">

var R = function()
{
	var t = this;
	t.leave = false;
	t.notice = '你的文章还没有进行保存！';
	
	t.pageStatus = function()
	{
		window.onbeforeunload = function (event){
			var evt = event || window.event;
			if(t.leave == true)
			{
				evt.returnValue = t.notice;
			}
		}
	}

	t.changeStatus = function()
	{
		switch(t.leave)
		{
			case false:
				t.leave = true;
			break;
			case true:
				t.leave = false;
			break;
		}	
	}

	t.print = function()
	{
		alert(t.leave)	
	}
}

var R = new R;
R.pageStatus();

</script>
</head>
<style>
	body{ margin:0px; padding:0px; font-size:12px; line-height:22px;}
	p{ margin:0px; padding:36px;}
</style>
<body>
	<p style="color:green;">点击提示按钮，刷新页面将会出现页面提示；再次点击，刷新页面将无提示！点击结果提示true表示会出现提示，出现false表示不会出现提示。</p>
	<input type=button value="提示" onclick="R.changeStatus();">
	<input type=button value="测试刷新" onclick="window.location.reload();">
	<input type=button value="结果" onclick="R.print();">
</body>
</html>